package main

import (
	handler "FILESTORE-SERVER/handler"
	"fmt"
	"net/http"
)

// func init() {
// 	http.HandleFunc("/file/upload", handler.UploadHandler)
// 	http.HandleFunc("/file/upload/suc", handler.UploadSucHandler)
// 	http.HandleFunc("/file/meta", handler.GetFileMetaHandler)
// 	http.HandleFunc("/file/query", handler.FileQueryHandler)
// 	http.HandleFunc("/file/download", handler.DownloadHandler)
// 	http.HandleFunc("/file/updata", handler.FileMetaUpdateHandler)
// 	http.HandleFunc("/file/delete", handler.FileDeleteHandler)
// 	http.HandleFunc("/user/signup", handler.SignupHandler)
// }

func main() {
	// 访问静态资源
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
	// 文件上传
	http.HandleFunc("/file/upload", handler.HTTPInterceptor(handler.UploadHandler))
	// 处理文件上传成功的重定向
	http.HandleFunc("/file/upload/suc", handler.HTTPInterceptor(handler.UploadSucHandler))
	http.HandleFunc("/file/meta", handler.HTTPInterceptor(handler.GetFileMetaHandler))
	http.HandleFunc("/file/query", handler.HTTPInterceptor(handler.FileQueryHandler))
	http.HandleFunc("/file/download", handler.HTTPInterceptor(handler.DownloadHandler))
	http.HandleFunc("/file/updata", handler.HTTPInterceptor(handler.FileMetaUpdateHandler))
	http.HandleFunc("/file/delete", handler.HTTPInterceptor(handler.FileDeleteHandler))
	http.HandleFunc("/file/fastupload", handler.HTTPInterceptor(handler.TryFastUploadHandler))

	http.HandleFunc("/user/signup", handler.SignupHandler)
	http.HandleFunc("/user/signin", handler.SignInHandler)

	// 分块接口
	//1、初始化分块信息
	http.HandleFunc("/file/mpupload/init", handler.HTTPInterceptor(handler.InitateMultiparUploadHandler))
	//2、上传分块
	http.HandleFunc("/file/mpupload/uppart", handler.HTTPInterceptor(handler.UploadPartHandler))
	//3、通知分块上传完成
	http.HandleFunc("/file/mpupload/complete", handler.HTTPInterceptor(handler.CompleteUploadPartHandler))

	// 查询用户信息
	http.HandleFunc("/user/info", handler.HTTPInterceptor(handler.UserInfoHandler))

	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		fmt.Printf("Failed to start server, err : %s", err.Error())
	}
}
